@controls-width: 130px;
@spatial-popup-background: @panel-bg;
@spatial-popup-text-color: @text-color;

.query-settings {
    width: @controls-width;
}

.query-save {
    .form-control {
        margin-right: -30px;
        opacity: 0;
        transition: opacity .2s cubic-bezier(0, 0.5, 0.5, 1), margin .2s cubic-bezier(0, 0.5, 0.5, 0.99);
    }

    &.active .form-control {
        opacity: 1;
        margin-right: 0px;
    }
}

.query-container {
    display: flex;

    .query-error {
        display: none;

        .help-block {
            margin-bottom: 0;
        }
    }

    .query-main {
        width: 100%;
        position: relative;
    }

    .query-controls {
        margin-top: 83px;
        margin-left: @line-height-computed/2;
        flex-basis: @controls-width;
        flex-shrink: 0;
        display: flex;
        flex-direction: column;

        .flex-separator {
            flex-grow: 100;
        }

        .statistics {
            align-self: flex-end;
        }
    }
}

#queryContainer {

    #spatialMap {

        #mapid {
            height: 100%;
            width: 100%;
        }

        .marker-cluster {
            color: @white;
        }

        .custom-popup .leaflet-popup-content-wrapper {
            background: @spatial-popup-background;
            color: @spatial-popup-text-color;
            font-size: 14px;
            line-height: 22px;
            overflow-wrap: break-word;
            width: 600px;
            border-radius: 3px;

            .leaflet-popup-content {
                margin: 0;
            }

            .leaflet-popup-scrolled {
                overflow-y: hidden;
            }

            h4 {
                color: @spatial-popup-text-color;
                padding: 0 @gutter-xs;
            }

            pre {
                max-height: 350px;
                white-space: pre-wrap;
                overflow-y: auto;
                background-color: @well-bg;
            }

            .leaflet-popup-scrolled {
                border-bottom: none;
                border-top: none;
            }
        }

        .custom-popup .leaflet-popup-tip-container {
            width: 30px;
            height: 15px;

            .leaflet-popup-tip {
                background: @spatial-popup-background;
            }
        }

        .leaflet-popup-close-button {
            color: @brand-danger;
            padding-top: 15px;
            padding-right: 30px;
        }

        .number-of-markers {
            background-color: lighten(@brand-info, 30%);
            border-radius: 5px;
        }
    }

    .virtual-grid {
        .cell {
            &.action-cell {
                text-align: center;

                .btn {
                    font-size: 20px;
                }
            }
        }
    }

    .query-results-container {
        .results-btn {
            color: @text-color;
            background-color: fadeout(@panel-bg, 30%);
            border: none;

            &.active {
                color: @text-emphasis;
                background-color: @panel-bg;
            }
        }
    }
}

.results-error {
    position: absolute;
    bottom: 0;
    width: 100%;
    .help-block {
        margin-bottom: 0;
    }
    z-index: 1000;
}

.show-add-filter {
    .query-error {
        position: absolute;
        bottom: 100%;
        width: 100%;
        display: block;
        z-index: @zindex-modal;
    }

    .backdrop {
        .backdrop.show;
    }

    .query-title, .run-query, .query-editor {
        position: relative;
        z-index: @zindex-modal;
    }

    .run-query {
        margin-top: 10px;
    }

    .query-source {        
        background-color: @gray-base;
        position: relative;
        z-index: @zindex-modal;
        margin-bottom: 0;
        .shadow-style;
    }

    .add-filter {
        z-index: @zindex-modal;
        display: block;
        .shadow-style;
    }
}

.results-info {
    small::after {
        content: " and"
    }

    small:last-child:after {
        content: "";
    }
}

.query-results-container {
    min-height: 480px;

    .js-time-series-graph-container > div {
        overflow-x: hidden;
    }

    .tabs-menu {
        .tooltip-inner {
            max-width: 350px;
            word-wrap: break-word;
        }

        .document-id {
            font-weight: 700;
        }
    }
}

.query-results {
    border: 1px solid @gray-darker;
    /*
    position: absolute;
    height: 100%;
    top:0;
    left:0;
    right:0;
    bottom:0;
    */

    tbody {
        overflow-y: auto;
    }

    td, th {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    th {
        &:hover {
            background-color: @gray-darker;
            cursor: pointer;
            span {
                text-decoration: underline;
            }
        }
    }
}

.queryPlan {
    pre {
        @color-list: @color-1, @color-1-2, @color-2, @color-2-2, @color-3, @color-3-2, @color-4, @color-4-2, @color-5, @color-5-2;
        .loop(@index) when (@index > 0) {
            @color: extract(@color-list, @index);

            .indent-@{index} {
                color: @color;
            }

            .loop(@index - 1);
        }
        .loop(length(@color-list));
    }
}

.js-timings-container {
    .timing-legend-item {
        div {
            margin-top: @gutter-xxs;
        }
    }

    &.timings {

        svg {
            .levelName {
                fill: @text-emphasis;
                text-anchor: middle;
                font-weight: bold;
                font-size: 14px;
            }

            .duration {
                fill: @text-color;
                font-size: 12px;
                text-anchor: middle;
            }
        }
        
        .color-def (@innerName, @color) {
            path {
                &.@{innerName} {
                    fill: @color;
                }
            }

            .item-rect {
                &.@{innerName} {
                    background-color: @color;
                }
            }
        }
        
        path {
            fill: @gray;
        }

        .item-rect {
            background-color: @gray;
        }

        .color-def(~'optimizer', @color-5-3);
        .color-def(~'query', @color-1);
        .color-def(~'retriever', @color-1-2);
        .color-def(~'projection', @color-2);
        .color-def(~'javaScript', @color-2-2);
        .color-def(~'load', @color-3);
        .color-def(~'storage', @color-3-2);
        .color-def(~'lucene', @color-4);
        .color-def(~'corax', @color-4);
        .color-def(~'includes', @color-4-2);
        .color-def(~'fill', @color-5);
        .color-def(~'gather', @color-5-2);
        .color-def(~'highlightings', @color-1-1);
        .color-def(~'setup', @color-1-3);
        .color-def(~'explanations', @color-2-1);
        .color-def(~'staleness', @color-2-3);
        .color-def(~'filter', @color-5-1);
        .color-def(~'terms', @color-3-1);
        .color-def(~'aggregateBy', @color-2-2);
    }

    .toggle {
        position: absolute;
        top: 10px;
        right: 20px;
    }

    .from-cache {
        position: absolute;
        bottom: 10px;
        left: 10px;
    }

    #container {
        background-color: pink;
        fill: hotpink;

        .levelName {
            color: @text-emphasis;
        }

        .duration {
            color: @text-color;
        }
    }

    .legend {
        position: absolute;
        top: 40px;
        left: 0;

        .item-rect {
            width: 12px;
            height: 12px;
            margin-right: 10px;
            display: inline-block;
            vertical-align: middle;
            margin-top: 3px;
        }

        .legend-item {
            padding-left: 20px;
            margin-top: @gutter-xs;

            .name {
                display: inline-block;
                width: 200px;
            }

            .duration {
                display: inline-block;
                text-align: right;
                width: 85px;
            }

            .legend-item {
                .name {
                    width: 180px;
                }

                .legend-item {
                    .name {
                        width: 160px;
                    }

                    .legend-item {
                        .name {
                            width: 140px;
                        }
                    }
                }
            }
        }
    }
}
